package com.ww.core.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.ww.core.R;
import com.ww.core.util.CoreSharedPreferencesHelper;
import com.ww.core.util.StringUtils;

public class TipDialog {
	private Context context;
	private String key;
	private Button close;

	public TipDialog(Context context) {
		key = context.getClass().getName() + "_tip";
		this.context = context;
	}

	public void show(int image) {
		show(image, null);
	}

	public void show(int image, String txt) {
		CoreSharedPreferencesHelper helper = new CoreSharedPreferencesHelper(context);
		if (helper.getValue(key) == null) {
			helper.setValue(key, "true");
			final Dialog dlg = new Dialog(context, R.style.MyDialog);
			dlg.show();
			Window window = dlg.getWindow();
			window.setContentView(R.layout.core_dialog_tip);

			TextView tip = (TextView) window.findViewById(R.id.txt);
			if (StringUtils.isNotEmpty(txt)) {
				tip.setText(txt);
				tip.setVisibility(View.VISIBLE);
			}

			ImageView imageView = (ImageView) window.findViewById(R.id.image);
			close = (Button) window.findViewById(R.id.but);

			if (image != -1) {
				imageView.setImageResource(image);
			}
			close.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					dlg.cancel();
				}
			});
		}
	}

}
